package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Employee;
import com.itheima.service.EmployeeService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/employee")
@RestController
public class EmployeeController {

    @Reference
    private EmployeeService employeeService;

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
            System.out.println(queryPageBean);
            PageResult pageResult = employeeService.findPage(queryPageBean);
            return pageResult;
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Employee employee){
        try {
            employeeService.add(employee);
           return new Result(true,null);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"添加失败");
        }
    }
}
